<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class pmember_model extends CI_Model {

	public function index($per_page ,$uri)
	{
		$this->db->limit($per_page ,$uri);
		$this->db->order_by('grant_end','desc');
		$query = $this->db->get('member');
		return $query->result_array();
	}

	public function get_member()
	{
		$query = $this->db->get('member');
		return $query->result_array();
	}

	public function search($input ,$per_page ,$uri)
	{
		$this->db->limit($per_page ,$uri);
		$this->db->like('mem_name',$input['search']);
		$this->db->or_like('mem_fname' ,$input['search']);
		$this->db->or_like('mem_lname' ,$input['search']);
		$this->db->or_like('mem_mail' ,$input['search']);
		$this->db->or_like('mem_address' ,$input['search']);
	 	$query = $this->db->get('member');
		return $query->result_array();
	}

	public function count_search($input)
	{
		$this->db->like('mem_name',$input['search']);
		$this->db->or_like('mem_fname' ,$input['search']);
		$this->db->or_like('mem_lname' ,$input['search']);
		$this->db->or_like('mem_mail' ,$input['search']);
		$this->db->or_like('mem_address' ,$input['search']);
	 	$query = $this->db->get('member');
		return $query->result_array();
	}

	public function register($input)
	{
		$this->db->insert('member',$input);
	}

	public function profile($uri)
	{
		$this->db->where('mem_id',$uri);
		$query = $this->db->get('member');
		return $query->result_array();
	}

	public function update($input)
	{
		$this->db->where('mem_id',$input['mem_id']);
		$this->db->update('member',$input);
	}

	public function check_user($input)
	{
		$this->db->select('mem_pass');
		$this->db->from('member');
		$this->db->where('mem_id',$input['check_id']);
		$this->db->where('mem_pass',$input['check_pass']);
		$this->db->limit(1);
		$query = $this->db->get();

		if($query -> num_rows() == 1){
    		return 1;

  		}else{
    		return 0;
 		}
	}

	public function check_already($input)
	{
		$this->db->select('mem_name');
		$this->db->from('member');
		$this->db->where('mem_name',$input['check_name']);
		$this->db->limit(1);
		$query = $this->db->get();

		if($query -> num_rows() == 1){
    		return 1;

  		}else{
    		return 0;
 		}
	}

	public function sum_status($priority)
	{
		$this->db->where('mem_type',$priority);
		$query = $this->db->get('member');
		return count($query->result_array());
	}

	public function change_role($input)
	{
		$this->db->where('mem_id' ,$input['mem_id']);
		$this->db->update('member' ,$input);
	}
	public function check_role($input)
	{
		$this->db->where('mem_id' ,$input['mem_id']);
		$this->db->select('mem_type');
		$query = $this->db->get('member');
		return $query->result_array();
	}

	public function delete_member($input)
	{
		$this->db->where('mem_id' ,$input['mem_id']);
		$this->db->delete('member');
	}

}